package com.peanut.baby.mvp.dingyue;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import android.widget.ImageView;
import android.widget.TextView;

import com.peanut.baby.R;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;


import java.util.List;

public class DingyueTagAdapter extends TagAdapter<String> {
    public static final int SET_HOT = 1;
    public static final int SET_RECOMMEND = 2;
    public static final int SET_SUBSCRIBED = 3;

    private Context ctx;
    private LayoutInflater inflater;
    private OnitemClickedListener listener;
    int setType;
    public DingyueTagAdapter(Context ctx,int setType, List<String> datas) {
        super(datas);
        this.ctx = ctx;
        this.setType = setType;
        inflater = LayoutInflater.from(this.ctx);
    }

    @Override
    public View getView(FlowLayout parent, int position, final String o) {
        View item = inflater.inflate(R.layout.layout_item_tag_dingyue,null, false);
        TextView view = item.findViewById(R.id.subscribe_text);
        ImageView icon = item.findViewById(R.id.subscribe_icon);

        if(setType == SET_HOT){
            icon.setImageResource(R.drawable.ic_check);
        }else{
            icon.setImageResource(R.drawable.ic_close);
        }

        view.setText(o);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.OnitemClicked(setType,position);
                }

            }
        });
        icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.OnitemClicked(setType,position);
                }
            }
        });
        return item;
    }



    public void setListener(OnitemClickedListener listener) {
        this.listener = listener;
    }

    public interface OnitemClickedListener{
        void OnitemClicked(int setType,int index);
    }
}
